package com.jymj.service.impl;

import com.jymj.dao.MoveCostDao;
import com.jymj.entity.MovecostEntity;
import com.jymj.entity.gantt.BaseDataEntity;
import com.jymj.entity.gantt.MoveCost;
import com.jymj.service.MoveCostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class MoveCostServiceImpl implements MoveCostService {

    @Autowired
    private MoveCostDao moveCostDao;

    @Override
    public BaseDataEntity getBaseDataById(Integer pjid) {
        Map map = new HashMap();
        map.put("pjid", pjid);
        return moveCostDao.getBaseDataById(map);
    }

    @Override
    public List<MoveCost> queryList(Integer pjid, int type) {
        Map map = new HashMap();
        map.put("pjid", pjid);
        map.put("type", type);
        return moveCostDao.queryList(map);
    }

    @Override
    public BaseDataEntity queryByPoint(String point, List<String> codeList, Integer pjid) {
        Map map = new HashMap();
        map.put("point", point);
        map.put("codeList", codeList);
        map.put("pjid", pjid);
        return moveCostDao.queryByPoint(map);
    }

    @Override
    public void updateCost(List<MoveCost> mCList) {
        if (mCList != null && !mCList.isEmpty()){
            moveCostDao.updateCost(mCList);
        }
    }

    @Override
    public List<MoveCost> getCostRTInvest(Integer pjid, int type) {
        Map map = new HashMap();
        map.put("pjid", pjid);
        map.put("type", type);
        return moveCostDao.getCostRTInvest(map);
    }

    @Override
    public MoveCost getChild(MoveCost moveCost) {
        return moveCostDao.getChild(moveCost);
    }

    @Override
    public int updateMovecost(MoveCost moveCost) {
        return moveCostDao.updateMovecost(moveCost);
    }

    @Override
    public void updateParent(MoveCost moveCost) {
        //查询是否有上一级
        MoveCost cost = moveCostDao.getParent(moveCost);
        if (cost == null){
            return;
        }
        moveCostDao.updateParent(moveCost);
        this.updateParent(cost);
    }

    @Override
    public void updateZtz(MoveCost moveCost) {
        moveCostDao.updateZtz(moveCost);
        moveCostDao.updateJkZtz(moveCost);
    }

    @Override
    public int updateBilprice(Integer costId, Integer pjid, BigDecimal bilprice) {
        return moveCostDao.updateBilprice(costId, pjid, bilprice);
    }

    @Override
    public List<MovecostEntity> queryList1(String code) {
        List<MovecostEntity> moveCostList = new ArrayList<>();
        if (code != null && !"".equals(code)){
            moveCostList = moveCostDao.queryList1(code);
        }else {
            moveCostList = moveCostDao.queryAll();
        }
        return moveCostList;
    }
}
